from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from items.ascii import Ascii
from core.support import get_game

class Register(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id) 
        
        self.add_item(Ascii())
        
        # build list of actions
        self.add_action(South)


    
    # return description of room.
    def get_description(self):
        return '''
        You see an open register containing a piece of a perfectly good ASCII translator for you to steal... I mean, "borrow."
        '''
    
    # return image of room
    def get_image(self):
        return 'cash_register_binary.jpg'
        #return 'binary_monster.jpg'
    
    def get_image_width(self):
        return 'width=100%'
    
    def is_translated(self):
        
        game = get_game()
            
        # does the player have the ASCII translator?
        player = game.get_player()
        
        if "Translator" in player.inventory:
            return True
        # if we get here, player does not have the translator
        return False

class RegisterHandler(BaseHandler):
    
    def get_template(self):
        return 'cpu.html'
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return Register

# define actions for this room

class South(Action):
    def __init__(self):
        Action.__init__(self, "South")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        game = get_game()
        room = game.get_room("register", Register)
        if room.is_translated():
            return "Go South"
        else:
            return "00"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'cpu'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def post_method(self):
        return "get"
    



